@echo off
@chcp 65001

setlocal enabledelayedexpansion

set currentPath=%~dp0

set codesPath=%currentPath%Codes\scripts
set clientPath=%currentPath%Cocos\assets\scripts
set serverPath=%currentPath%Server\scripts

set linkList0=Codes
set linkList1=Core
set linkList2=Decorator
set linkList3=Support

@REM 客户端代码处理

FOR /l %%i IN (0,1,3) do (
    IF EXIST %clientPath%\!linkList%%i! (
        echo Try to remove dir %clientPath%\!linkList%%i!
        rmdir /s /q %clientPath%\!linkList%%i!
    )
    IF EXIST %clientPath%\!linkList%%i! (
        echo Try to delete link %clientPath%\!linkList%%i!
        del /q %clientPath%\!linkList%%i!
    )
)

set clientCodes=%clientPath%\Codes
IF NOT EXIST %clientCodes% (
	mkdir %clientCodes%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Client Folder created successfully: %clientCodes%
	)
)

set clientHotfix=%clientPath%\Codes\Hotfix
IF NOT EXIST %clientHotfix% (
	mkdir %clientHotfix%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Client Folder created successfully: %clientHotfix%
	)
)

set clientHotfixView=%clientPath%\Codes\HotfixView
IF NOT EXIST %clientHotfixView% (
	mkdir %clientHotfixView%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Client Folder created successfully: %clientHotfixView%
	)
)

set clientModel=%clientPath%\Codes\Model
IF NOT EXIST %clientModel% (
	mkdir %clientModel%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Client Folder created successfully: %clientModel%
	)
)

set clientModelView=%clientPath%\Codes\ModelView
IF NOT EXIST %clientModelView% (
	mkdir %clientModelView%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Client Folder created successfully: %clientModelView%
	)
)

set clientModelGenerate=%clientPath%\Codes\Model\Generate
IF NOT EXIST %clientModelGenerate% (
	mkdir %clientModelGenerate%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Client Folder created successfully: %clientModelGenerate%
	)
)

set clientSupport=%clientPath%\Support
IF NOT EXIST %clientSupport% (
	mkdir %clientSupport%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Client Folder created successfully: %clientSupport%
	)
)

mklink /D %clientPath%\Core %codesPath%\Core
mklink /D %clientPath%\Codes\Hotfix\Share %codesPath%\Codes\Hotfix\Share
mklink /D %clientPath%\Codes\Hotfix\Client %codesPath%\Codes\Hotfix\Client
mklink /D %clientPath%\Codes\HotfixView\Client %codesPath%\Codes\HotfixView\Client
mklink /D %clientPath%\Codes\Model\Share %codesPath%\Codes\Model\Share
mklink /D %clientPath%\Codes\Model\Client %codesPath%\Codes\Model\Client
mklink /D %clientPath%\Codes\ModelView\Client %codesPath%\Codes\ModelView\Client
mklink /D %clientPath%\Codes\Model\Generate\Share %codesPath%\Codes\Model\Generate\Share
mklink /D %clientPath%\Codes\Model\Generate\Client %codesPath%\Codes\Model\Generate\Client
mklink /D %clientPath%\Decorator %codesPath%\Decorator
mklink /D %clientPath%\Support\Share %codesPath%\Support\Share
mklink /D %clientPath%\Support\Client %codesPath%\Support\Client

@REM 服务器代码处理

FOR /l %%i IN (0,1,3) do (
    IF EXIST %serverPath%\!linkList%%i! (
        echo Try to remove dir %serverPath%\!linkList%%i!
        rmdir /s /q %serverPath%\!linkList%%i!
    )
    IF EXIST %serverPath%\!linkList%%i! (
        echo Try to delete link %serverPath%\!linkList%%i!
        del /q %serverPath%\!linkList%%i!
    )
)
set serverCodes=%serverPath%\Codes
IF NOT EXIST %serverCodes% (
	mkdir %serverCodes%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Server Folder created successfully: %serverCodes%
	)
)

set serverHotfix=%serverPath%\Codes\Hotfix
IF NOT EXIST %serverHotfix% (
	mkdir %serverHotfix%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Server Folder created successfully: %serverHotfix%
	)
)

set serverModel=%serverPath%\Codes\Model
IF NOT EXIST %serverModel% (
	mkdir %serverModel%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Server Folder created successfully: %serverModel%
	)
)

set serverModelGenerate=%serverPath%\Codes\Model\Generate
IF NOT EXIST %serverModelGenerate% (
	mkdir %serverModelGenerate%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Server Folder created successfully: %serverModelGenerate%
	)
)

set serverSupport=%serverPath%\Support
IF NOT EXIST %serverSupport% (
	mkdir %serverSupport%
	
	IF %ERRORLEVEL% EQU 0 (
		echo Client Folder created successfully: %serverSupport%
	)
)

mklink /D %serverPath%\Core %codesPath%\Core
mklink /D %serverPath%\Codes\Hotfix\Share %codesPath%\Codes\Hotfix\Share
mklink /D %serverPath%\Codes\Hotfix\Server %codesPath%\Codes\Hotfix\Server
mklink /D %serverPath%\Codes\Model\Share %codesPath%\Codes\Model\Share
mklink /D %serverPath%\Codes\Model\Server %codesPath%\Codes\Model\Server
mklink /D %serverPath%\Codes\Model\Generate\Share %codesPath%\Codes\Model\Generate\Share
mklink /D %serverPath%\Codes\Model\Generate\Server %codesPath%\Codes\Model\Generate\Server
mklink /D %serverPath%\Decorator %codesPath%\Decorator
mklink /D %serverPath%\Support\Share %codesPath%\Support\Share
mklink /D %serverPath%\Support\Server %codesPath%\Support\Server

pause